import pandas as pd
from matplotlib import pyplot as plt

'''
代码提示：
1. 使用 Pandas 读取 JSON 文件数据
2. 获取重复的用户 ID 数据
3. 求解每位用户对应的总学习时长
4. 绘制线型图
5. 设置图标题及坐标轴名称
'''

def data_plot():

    fig = plt.figure()

    ax = fig.add_subplot(1,1,1)# 设置子图对象 ax

    stu_data = pd.read_json('./Code/shiyanlou/pandas/user_study.json',orient='records',encoding='utf-8')
    data = stu_data[['user_id','minutes']].groupby('user_id',as_index=False).sum()

    # 设置 X, Y 轴 标签
    ax.set_xlabel("User ID")
    ax.set_ylabel("Study Time")
    # 设置标题
    ax.set_title("StudyData")

    # 按要求绘制图像
    ax.plot(data['user_id'],data['minutes'])
    plt.show()

    # 务必返回子图对象 ax
    return ax


if __name__=='__main__':
    print(data_plot())

data = pd.read_csv('~/Documents/Code/shiyanlou/pandas/apple.json',header=0)
